All Questions
47 questions
1vote
1answer
110views
Bash: How to read the script when sourcing it
When bash is executing a script, ls -la /proc/<pid of bash>/fd shows "255 -> /path/to/script". I think that bash reads the script via file discriptor 255, and executes the commands ...
0votes
1answer
824views
How can I loop over all directories and subdirectories and find files with a specific extension, then run FFMPEG on them, then copy them to a new lib
Ive been researching all of today and yesterday trying to find a solution, none have worked for me so far. For example: https://stackoverflow.com/questions/5784661/how-do-you-convert-an-entire-...
2votes
3answers
613views
Move files to directory according to the content pattern matching
I would like to move files in existing directory files containing specific content to an existing or new directory and subdirectory by writing a script called fruit in ~/bin that moves them to dir/...
1vote
1answer
94views
Delete sub-directories based on matching information from column
I want to keep only those sub-directories that are present in the corresponding directory from CSV file. The file structure looks something like this: 100_folder/ ├── folder_11 ├── folder_25 ├── ...
0votes
1answer
847views
File is having lots of special characters. How to replace?
I have a file with record like: CENTURY®KETTLEBELLS COLEMANTT40°BAG AlphaPro2¾TDLE Lot™Stretch M6×30 It shows normally in notepad files but in terminal when i cat it, it shows: CENTURY▒KETTLEBELL ...
1vote
3answers
242views
I want to write a bash script to separate characters from special characters?
I am new to bash. I want to write a bash script where I have a file, "file.txt". I want to cut & paste normal characters to charecters.txt & special characters to special.txt. ...
2votes
2answers
201views
How do I delete all directories with a certain file type in them?
I'm writing a command line script to 'unpack' folders with .svg files from downloads. I've copied the required files to a specific directory and now I need to delete all the directories with .svg ...
1vote
1answer
382views
How to rename nested folders?
So I have a bunch of folders in the format of: .../course/year/... and I often reorganize them so that the format then changes to this: .../year/course/.... I've been meaning to learn how to write ...
2votes
2answers
139views
How to find same filename but different content
I am trying to find the textfiles that have the same name but contain different content from two different directories. The following is my code but it keeps crashing here cati=`ls $1 | cat $i` ...
2votes
3answers
3kviews
How can I reliably determine if a file is an image file? [duplicate]
Currently I'm using the following command: file image.jpg | cut -d " " -f 2 So far so good. It works on a file without an image extension too. So, I was wondering if there's another way to do this? I ...
-1votes
3answers
952views
How do I create always 4 digit sequentially numbered and named file with shell script
I'm trying to create multiple *.txt files with 4-digit numerical names with leading zeros when needed. Script needs to stop when MAX varialbe is reached. This is using /bin/sh (not bash) but any ...
1vote
2answers
150views
Generate the output of the file in the next line
I have 3 files ex- abc.txt, def.txt & xyz.txt. I've generate one shell script where I want to content of these 3 files should appear line wise like as below- abc ---- 1 2 3 4 5 6 7 def ----...
2votes
1answer
103views
I have an issue with a script that does file manipulation
Ive been working on a script that instantaneously detects files created in the Downloads directory then sorts them based on file extension. The issue with this however is that when downloading a file ...
12votes
6answers
17kviews
Checking for the existence of multiple directories
I want to check for the existence of multiple directories, say, dir1, dir2 and dir3, in the working directory. I have the following if [ -d "$PWD/dir1" ] && [ -d "$PWD/dir2" ] && [ -...
1vote
2answers
72views
Comparison of two values from two list
I am trying to compare two strings. One value is coming from iptables and the other is from a file where I saved previous records. I want to identify if there is a new user appear in iptables. If so ...